package main

import (
	"os"
	"strconv"
	"time"
)

func main() {
	timeStart := time.Now().UnixNano()
	time.Sleep(1 * time.Second)
	FileTimeData("E:\\Go_project\\src\\e-coupon\\experiment\\a.txt", "8000", timeStart, 5)
}

// 记录程序步骤运行时间
func FileTimeData(filePath, nodeID string, timeStart, committeeNum int64) {
	var f *os.File

	_, err := os.Stat(filePath)
	if err == nil {
		f, _ = os.OpenFile(filePath, os.O_APPEND, 6)
	} else {
		f, _ = os.Create(filePath)
	}

	timeEnd := time.Now().UnixNano() // 纳秒

	// 纳秒转毫秒然后存储
	f.WriteString(
		nodeID + "," +
			strconv.Itoa(int((timeEnd-timeStart)/1e6)) +
			"," +
			strconv.Itoa(int(committeeNum)) +
			"\n")
}
